package game.entity.process;

import game.entity.mob.Mob_Entity;
import game.gamestate.GameState;
import game.physics.CollisionGroup_I;
import game.physics.MapCollision;

import java.util.LinkedList;
import java.util.List;
import common.Rectangle;

public class CollisionProcess implements EntityProcessor_I<Mob_Entity> {

	@Override
	public int process(List<Mob_Entity> entities, GameState gameState, int time) {
		CollisionGroup_I collisionGroup = gameState.GameMap.getBlockMap();
		Rectangle hitBox;
		// Check collision with map.
		for(Mob_Entity mob : entities) {
			hitBox = mob.Body.HitBox.clone();
			hitBox.X += mob.Body.Location.X;
			hitBox.Y += mob.Body.Location.Y;
			LinkedList<MapCollision> collisions = collisionGroup.collide(hitBox);
			if(collisions != null) {
				for(MapCollision collision : collisions) {
					mob.collide(collision, time);
				}
			}
		}
		return entities.size();
	}
}